package com.wdb007.venus.wss.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wdb007.venus.svc.facade.BookgridService;
import com.wdb007.venus.wss.service.WebSocketServerService;

import io.netty.channel.ChannelHandlerContext;

@Service("bookGridStatusFixedResService")
public class BookGridStatusFixedResService implements WebSocketServerService {

	private static Logger logger = LoggerFactory.getLogger(BookGridStatusFixedResService.class);
	
	@Autowired
	private BookgridService bookgridService;
	
	@Override
	public String doService(ChannelHandlerContext ctx, String request) throws Exception {
		JSONObject jsonObj = JSON.parseObject(request);
//		logger.info("BookGridStatusFixed 接收websocket响应信息: {}", jsonObj.toJSONString());
		try {
			
			String bookGridId = jsonObj.getString("bookGridId");
			String status = jsonObj.getString("status");
			logger.info("debug {}: 书格{}, 响应内容{}", jsonObj.getString("action"), bookGridId,jsonObj.toJSONString());
			bookgridService.bookGridStatusReport(bookGridId, status);
		} catch (Exception e) {
			logger.error("单书格状态上报(定时)异常", e);
		}
		return null;
	}

}
